

function getdata(e) {

	var personId = $("#personId").val();
	if(personId == "")
		return;
	else {
		document.getElementById("prevouspage").style.display = "none";// 隱藏
		document.getElementById("nextpage").style.display = "none";// 隱藏
		document.getElementById("deldata").style.display = "inline";// 隱藏
		
		$.ajax({ 
			type : "POST",
			url : "suggestSearch.do",
			dataType : 'text',
			
			data : {
				type : "suggestsearch",
				id : $("#personId").val(),
				count : "0"
			},

			error : function(xhr) {
				alert("Ajax request error!");

			},
			
			success : function(DataList) {
				var data = DataList.split("|");
				
				if (data[0].split(":")[0] == "nextpage") {
					document.getElementById("nextpage").style.display = data[0].split(":")[1];
					$("#count").val(data[1]);
					$("#suggesthistory").html(data[2]);
				} else {
					$("#suggesthistory").html(DataList);
				}
			}
		});				
	}
}
//-----------------------------------------------------------------------
function nextpage(e) { //下一頁
	$.ajax({
		type : "POST",
		url : "suggestSearch.do",
		dataType : 'text',

		data : {
			type : "nextpage",
			id : $("#personId").val(),
			count : $("#count").val()
		},

		error : function(xhr) {
			alert("Ajax request error!");

		},
		
		success : function(DataList) {
			var data = DataList.split("|");
			if (data[0].split(":")[0] == "nextpage")
				document.getElementById("nextpage").style.display = data[0].split(":")[1];
			if (data[1].split(":")[0] == "prevouspage")
				document.getElementById("prevouspage").style.display = data[1].split(":")[1];
			$("#count").val(data[2]);
			$("#suggesthistory").html(data[3]);
		}
	});
}

//-----------------------------------------------------------------------
function prevouspage(e) { //上一頁
	$.ajax({
		type : "POST",
		url : "suggestSearch.do",
		dataType : 'text',

		data : {
			type : "prevouspage",
			id : $("#personId").val(),
			count : $("#count").val()
		},

		error : function(xhr) {
			alert("Ajax request error!");

		},
		
		success : function(DataList) {
			var data = DataList.split("|");
			if (data[0].split(":")[0] == "nextpage")
				document.getElementById("nextpage").style.display = data[0].split(":")[1];
			if (data[1].split(":")[0] == "prevouspage")
				document.getElementById("prevouspage").style.display = data[1].split(":")[1];
			$("#count").val(data[2]);
			$("#suggesthistory").html(data[3]);
		}
	});
}
//-----------------------------------------------------------------------
function deldata(e) {	//刪除資料
	var data = "";

	$("#div_data input:checked").each(function () {
		if (data.length > 0) {
			data = data + "; ";
		}
		data = data + $(this).val();
	});
	
	$.ajax({
		type : "POST",
		url : "suggestSearch.do",
		dataType : 'text',
		
		data : {
			type : "deldata",
			datalist : data,
			count : 0
		},
		
		success : function(data) {
			if (data == "error") {
				alert("刪除失敗");
			} else if (data == "succ") {
				alert("刪除成功");
				getdata();
			}
		},
		
		error : function(e) {
			alert("Ajax request error!");
		}
				
	});
}

$(document).ready(function(e) {

	document.getElementById("prevouspage").style.display = "none";// 隱藏
	document.getElementById("nextpage").style.display = "none";// 隱藏
	document.getElementById("deldata").style.display = "none";// 隱藏
	
	$("#getdata").on("click",getdata); //讀取ID歷史紀錄
	$("#prevouspage").on("click",prevouspage); //上一頁
	$("#nextpage").on("click",nextpage); //下一頁
	
	$("#deldata").on("click", deldata);

});